<template>
  <div>
    <el-dialog
      title="批阅作业"
      :visible.sync="dialogVisible"
      width="600px"
      @closed="resetForm('form')"
      :close-on-click-modal="false"
    >
      <div>
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-form-item label="评分" prop="score">
            <el-input v-model.trim="form.score"></el-input>
          </el-form-item>

          <el-form-item label="内容" prop="content">
            <el-input
              type="textarea"
              :rows="4"
              placeholder="请输入内容"
              v-model="form.content"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="custom" v-preventReClick @click="submitForm('form')"
          >提 交</el-button
        >
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { eduTeacherCommentsAdd } from '@/api/admin/teach/eduTeacherComments.js'

export default {
  data() {
    return {
      title: '新增',
      dialogVisible: false,
      form: {
        content: '', //内容
        score: '', //评分
        studentJobsId: '', //作业id
      },
      rules: {
        score: [{ required: true, message: '请输入评分', trigger: 'blur' }],
      },
    }
  },
  mounted() {
    this.$bus.$on('showDialogCheckAnswer', this.init)
  },
  beforeDestroy() {
    this.$bus.$off('showDialogCheckAnswer')
  },
  methods: {
    //显示弹窗
    init(row) {
      this.form.studentJobsId = row.id
      this.dialogVisible = true
    },
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          this.add()
        }
      })
    },
    //新增
    add() {
      eduTeacherCommentsAdd(this.form).then((res) => {
        this.done()
      })
    },
    done() {
      this.dialogVisible = false
      // Bus.$emit('refreshBannerList')
      this.$message({
        message: '操作成功',
        type: 'success',
      })
    },
    //重置表单
    resetForm(form) {
      this.$refs[form].resetFields()
    },
  },
}
</script>